package v1

import (
	"gohub/app/requests"
	"gohub/pkg/chat"
	"gohub/pkg/config"
	"net/http"

	"github.com/gin-gonic/gin"
)

type ChatController struct {
	BaseAPIController
}

func (ctrl *ChatController) ChatCompletion(c *gin.Context) {
	var req requests.ChatRequest
	if err := c.ShouldBindJSON(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}

	response, err := chat.NewCHAT().ChatCompletion(chat.Message{
		Template: config.GetString("chat.siliconflow.template_code"),
	})
	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
		return
	}

	c.JSON(http.StatusOK, response)
}
